package negocio;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;


//Replace to Data Class
//Finish, nada mas a agregar a modificar en esta Clase!!!!!
public class BDFileObjectProperties{

	//Path Home of DBFileProperties
	  private static final String homeUserWindows  = System.getProperty("user.home");
	  private static final String separatorFile = File.separator;
	  private static final String SACIPathDBFileProperties = homeUserWindows+separatorFile+".SACI";
	  
	  public static final String dbAccesPropertiesPathUserWindows =SACIPathDBFileProperties+separatorFile+"DBAccesProperties.conf";
	
	  
	public static void escribirObjectBDAccesPropertiesFromFileName(Object anObject, String filename) throws Exception {
	    
		new File(SACIPathDBFileProperties).mkdirs(); //Crea carpetas de acceso, si no existen
		FileOutputStream f = new FileOutputStream(filename);
	    System.out.println("Nombre del nuevo archivo en que se ESCRIBE Objeto: "+filename);
	    
	    ObjectOutputStream out = new ObjectOutputStream(f);
	    out.writeObject(anObject);
	    f.close();
	  }

	public static Object leerObjectBDAccesPropertiesFromFileName(String filename) throws Exception {
		    FileInputStream f = new FileInputStream(filename);
		    
		    System.out.println("Nombre del nuevo archivo en que se LEE Objeto: "+filename);
		    ObjectInputStream in = new ObjectInputStream(f);
		    Object o = in.readObject();
		    f.close();
		    return o;
		  }

}
